<?php
namespace app\api\controller\v2;
use app\api\controller\Common;

class OrderAmount extends Common{
	var $modelDb;
	public function _initialize(){
		parent::_initialize();
		$this->modelDb = model("OrderAmount");
	}
	public function chongzhi(){
        $totalprice = $this->postData['totalprice'];
        if (empty($totalprice)) {
        	return $this->app_error('请输入金额！');
        }
		$this->postData['userid'] = $this->uinfo['id'];
		// $result = $this->validate($this->postData, 'Member.check_price');
		// if ($result !== true) {
		// 	return $this->app_error($result);
		// }
		list($bool, $data) = $this->modelDb->save_datas($this->postData);
		if ($bool !== true) {
			return $this->app_error($bool);
		}else{
			return $this->app_success($data);
		}
	}
	public function tixian(){
		if ($this->postData['totalprice'] < config('DEPOSIT_MINPRICE')) {
			return $this->app_error('提现金额不能低于'.config('DEPOSIT_MINPRICE').'元');
		}
		if ($this->postData['totalprice'] > $this->uinfo['amount']) {
			return $this->app_error('余额不足');
		}
		$this->postData['userid'] = $this->uinfo['id'];
		$this->postData['province'] = model("City")->where('id', $this->postData['province'])->value('title');
		
		$result = $this->validate($this->postData, 'Member.check_paytype');
		if ($result !== true) {
			return $this->app_error($result);
		}
		$id = model("OrderDeposit")->save_datas($this->postData);
		if (!$id) {
			return $this->app_error(model("OrderDeposit")->getError());
		}
		$id = model("MemberCard")->save_datas($this->postData);
		return $this->app_success();
	}
}